package com.matrix.java.chap_07;

import com.matrix.java.util.ArrayUtil;

public class Ex7_14 {
    public static void main(String[] args) {
        int[] arr = {33, 55, 66, 77, 88};
        System.out.println(gcd(arr));
    }

    //另一种方法，找出最小数的约数，形成数组，一一校验，或可找出最大约数
    public static int gcd(int... numbers) {
        int minInArray = ArrayUtil.findMinInArray(numbers);
        int maxDivisor = 0;
        for (int i = 2; i <= minInArray; i++) {
            int count = 0;
            for (int number : numbers) {
                if (number % i != 0) {
                    break;
                } else {
                    count++;
                }
            }
            if (count == numbers.length) {
                maxDivisor = i;
            }
        }
        return maxDivisor;
    }
}
